<template>
<table
    class="gas-cp-container"
    border="1">
    <tr class="top-container">
        <td class="left">
            H2S含量—CO2含量相关关系判别 基础数据
        </td>
        <td class="right">
            当前报告
        </td>
    </tr>
    <tr class="content-container">
        <td class="left">
            <div class="container">
                <div class="chart">
                    <MyChart
                        ref="MyChart">
                    </MyChart>
                </div>
                <div class="base-data">
                    <table border="1">
                        <tr>
                            <th colspan="2">A区(大安寨组，须家河组，雷四段，嘉二段)</th>
                        </tr>
                        <tr>
                            <td class="cols1">H2S%</td>
                            <td class="cols2">CO2%</td>
                        </tr>
                        <tr>
                            <td class="cols1">0.25%>H2S</td>
                            <td class="cols2">6.00%>CO2>0.00%</td>
                        </tr>
                        <tr>
                            <th colspan="2">B区(龙王庙组)</th>
                        </tr>
                        <tr>
                            <td class="cols1">H2S%</td>
                            <td class="cols2">CO2%</td>
                        </tr>
                        <tr>
                            <td class="cols1">0.90%>H2S>0.25%</td>
                            <td class="cols2">2.50%>CO2>1.00%</td>
                        </tr>
                        <tr>
                            <th colspan="2">C区(灯影组)</th>
                        </tr>
                        <tr>
                            <td class="cols1">H2S%</td>
                            <td class="cols2">CO2%</td>
                        </tr>
                        <tr>
                            <td class="cols1">2.1%>H2S>1.20%</td>
                            <td class="cols2">5.0%>CO2>3.50%</td>
                        </tr>
                        <tr>
                            <th colspan="2">D区(飞仙关组，栖霞组，茅口组)</th>
                        </tr>
                        <tr>
                            <td class="cols1">H2S%</td>
                            <td class="cols2">CO2%</td>
                        </tr>
                        <tr>
                            <td class="cols1">3.00%>H2S>1.15%</td>
                            <td class="cols2">3.50%>CO2>1.9%</td>
                        </tr>
                        <tr>
                            <th colspan="2">E区(雷一段)</th>
                        </tr>
                        <tr>
                            <td class="cols1">H2S%</td>
                            <td class="cols2">CO2%</td>
                        </tr>
                        <tr>
                            <td class="cols1">3.00%>H2S>1.15%</td>
                            <td class="cols2">1.90%>CO2>0.00%</td>
                        </tr>
                    </table>
                </div>
            </div>
        </td>
        <td>
            <div class="right-container">
                <MyChart
                    class="chart"
                    ref="MyChart1">
                </MyChart>
            </div>
        </td>
    </tr>
    <tr class="bottom-container" v-if="false">
        <td
            colspan="2"
            class="container">
            低熟油型气
        </td>
    </tr>
</table>
</template>
<script>
/*
 H2S含量—CO2含量相关关系判别展示页面
 */
import {randomColor} from "@/common/ColorTools";
import {computedRem,randomEchartSymbol} from '@/common/OtherTools';
import MyChart from '@/components/MyChart';
import {debounceFn} from '@/common/DebounceAndThrottle';
export default {
    components:{MyChart},
    props:{
        reports:{  //当前选择的报告列表
            type:Array,
            default:()=>[],
        },
        areas:{  //当前选择的井号
            type:Array,
            default:()=>[],
        },
        horizons:{  //当前选择的层位
            type:Array,
            default:()=>[],
        },
        fontColor:{
            type:String,
            default:'',
        },
        borderColor:{
            type:String,
            default:'',
        },
        chartBorderColor:{
            type:String,
            default:'',
        },
    },
    data() {
        this.nameConfigMap = {};  //数据根据名称的配置
        return {
        };
    },
    watch:{
        reports(){
            this.getReportData();
        },
    },
    mounted(){
        this.getBaseData();
    },
    methods:{
        formatData(data){  //格式化数据
            data = data || {};
            Object.keys(data).forEach(item=>{
                this.nameConfigMap[item] = this.nameConfigMap[item] || {
                    color:randomColor(),
                    symbol:randomEchartSymbol(),
                };
            });
            return data;
        },
        getBaseData(){  //获取基础数据
            this.$Service.post(
                this.$Api.findByH2s,
                {
                    "isbasic":1,
                },
            ).then(data => {
                let target = this.$refs.MyChart;
                this.drawChart({
                    target,
                    data:this.formatData(data.data),
                });
            }).catch(() => {
                return;
            });
        },
        getReportData:debounceFn(function(){  //获取报告数据
            let target = this.$refs.MyChart1;
            if(this.reports.length == 0){
                this.drawChart({target,data:[]});
                return;
            }
            this.$Service.post(
                this.$Api.findByH2s,
                {
                    "reportType":2,
                    "reportNo":this.reports.join(","),
                    'area':this.areas.join(','),
                    'horizon':this.horizons.join(','),
                },
            ).then(data => {
                this.drawChart({
                    target,
                    data:this.formatData(data.data),
                });
            }).catch(() => {
                this.drawChart({target,data:[]});
                return;
            });
        },700),
        drawChart({target,data={}}){  //绘制表格
            let rem = computedRem();
            var option = {
                grid: {
                    left: '10%',
                    right: '5%',
                    top: '15%',
                    bottom: '15%',
                },
                tooltip: {
                    trigger: 'item',
                    formatter: params=>{
                        if(!params.value) return;
                        return `${params.name}<br>${params.value[0]}  ,  ${params.value[1]}`;
                    },
                },
                xAxis: {
                    type: 'value',
                    name: 'H2S%',
                    nameLocation:'center',
                    nameGap:40,
                    nameTextStyle:{
                        fontWeight:'bold',
                        fontSize:1*rem,
                    },
                    splitArea: {
                        show: false,
                    },
                    axisLine: {
                        show:true,
                        lineStyle: {  //y轴样式
                            color:this.fontColor,
                        },
                    },
                    splitLine: {//分割线配置
                        show:false,
                    },
                    min: 0.0,
                    max: 3.0,
                },
                yAxis: {
                    type: 'value',
                    name: 'CO2%',
                    nameLocation:'center',
                    nameGap:40,
                    nameTextStyle:{
                        fontWeight:'bold',
                        fontSize:1*rem,
                    },
                    splitArea: {
                        show: false,
                    },
                    axisLine: {
                        show:true,
                        lineStyle: {  //y轴样式
                            color:this.fontColor,
                        },
                    },
                    splitLine: {//分割线配置
                        show:true,
                        lineStyle: {
                            color: this.borderColor,
                        }
                    },
                    min: 0.0,
                    max: 7.0,
                },
                legend:{
                    type: 'scroll',
                    data: Object.keys(data).map(item=>{
                        return {
                            name: item,
                            icon: this.nameConfigMap[item].symbol,
                            itemStyle:{
                                color: this.nameConfigMap[item].color,
                            },
                            textStyle: {
                                color: this.nameConfigMap[item].color,
                            },
                        };
                    }),
                },
                series: [
                    ...Object.keys(data).map(item=>{
                        return {
                            symbolSize: 1*rem,
                            name:item,
                            data: data[item].map(item_=>{
                                return {
                                    name:item,
                                    value:[item_.xaxis,item_.yaxis],
                                    symbol:this.nameConfigMap[item].symbol,
                                    itemStyle:{
                                        color:this.nameConfigMap[item].color,
                                    },
                                };
                            }),
                            type: 'scatter'
                        };
                    }),
                    //标记线配置
                    {
                        type: 'line',
                        showSymbol: false,
                        smooth: true,
                        silent:true,
                        lineStyle:{
                            color:'red',
                            width:1,
                        },
                        data: [[0.25, 0],[0.25,7]],
                        markLine: {  //标记线，文本配置
                            symbol:false,
                            animation:false,
                            label:{
                                color:this.fontColor,
                                fontWeight:'bold',
                                fontSize:1*rem,
                            },
                            data:[
                                [
                                    {
                                        label:{
                                            formatter:'A',
                                        },
                                        coord: [0.1, 4.0],
                                    },
                                    {
                                        coord: [0.1, 4.0]
                                    }
                                ],
                                [
                                    {
                                        label:{
                                            formatter:'B',
                                        },
                                        coord: [0.56, 4.0],
                                    },
                                    {
                                        coord: [0.56, 4.0]
                                    }
                                ],
                                [
                                    {
                                        label:{
                                            formatter:'C',
                                        },
                                        coord: [2.0, 5.0],
                                    },
                                    {
                                        coord: [2.0, 5.0]
                                    }
                                ],
                                [
                                    {
                                        label:{
                                            formatter:'D',
                                        },
                                        coord: [1.25, 2.5],
                                    },
                                    {
                                        coord: [1.25, 2.5]
                                    }
                                ],
                                [
                                    {
                                        label:{
                                            formatter:'E',
                                        },
                                        coord: [1.25, 1.0],
                                    },
                                    {
                                        coord: [1.25, 1.0]
                                    }
                                ],
                            ],
                        },
                    },
                    {
                        type: 'line',
                        showSymbol: false,
                        smooth: true,
                        silent:true,
                        lineStyle:{
                            color:'#409eff',
                            width:1,
                        },
                        data: [[0.9, 0],[0.9,7]],
                    },
                    {
                        type: 'line',
                        showSymbol: false,
                        smooth: true,
                        silent:true,
                        lineStyle:{
                            color:'#ffffff',
                            width:1,
                        },
                        data: [[0.9, 3.5],[3.0,3.5]],
                    },
                    {
                        type: 'line',
                        showSymbol: false,
                        smooth: true,
                        silent:true,
                        lineStyle:{
                            color:'blue',
                            width:1,
                        },
                        data: [[0.9, 1.9],[3.0,1.9]],
                    },
                ],
            };
            target && target.setOption(()=>option);
        },
    },
};
</script>
<style scoped lang="scss">
.gas-cp-container{
    width: 100%;
    height: fit-content;
    text-align: left;
    color: var(--font-color);
    box-sizing: border-box;
    border-collapse: collapse;
    border-color: var(--border-color);
    border: 1px solid var(--border-color);
    table-layout:fixed;
    >tr{
        >td{
            &:last-child{
                width: 50%;
            }
        }
    }
    >.top-container{
        >td{
            font-size: 1.5rem;
            font-weight: bold;
            padding: 1rem;
            box-sizing: border-box;
            line-height: 1;
            box-sizing: border-box;
        }
    }
    >.content-container{
        >.left{
            >.container{
                display: grid;
                grid-template-columns: 1fr;
                >.chart{
                    width: 100%;
                    height: 30rem;
                }
                >.base-data{
                    padding: 0 1rem 1rem 1rem;
                    box-sizing: border-box;
                    width: 100%;
                    text-align: center;
                    display: grid;
                    grid-gap: 1rem;
                    height: fit-content;
                    >.base-data-title{
                        font-size: 1.5rem;
                    }
                    >table{
                        width: 100%;
                        height: fit-content;
                        border-collapse: collapse;
                        border-color: #0f4b78;
                        border: 1px solid #0f4b78;
                        td,th{
                            padding:5px;
                            text-align: center;
                            font-size: 14px;
                            box-sizing: border-box;
                        }
                        th{
                            font-size: 16px;
                            font-weight: bold;
                            background-color: #009159;
                        }
                        .cols2,.cols4,.cols6{
                            width: 50%;
                        }
                    }
                }
            }
        }
        .right-container{
            height: 100%;
            >.chart{
                width: 100%;
                height: 30rem;
            }
        }
    }
    >.bottom-container{
        >.container{
            padding: 1.5rem 1rem;
            font-size: 1.5rem;
            color: #99a9bf;
            box-sizing: border-box;
            span{
                font-size: 1.7rem;
                color: var(--font-color);
            }
            .data{
                font-size: 2rem;
                color: #00c57a;
                font-weight: bold;
            }
        }
    }
}
</style>
